package acm.蓝桥12;

import java.util.Scanner;

//可以通过前n项和快速找出l
public class 序列和 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            long l = sc.nextLong();
            long r = sc.nextLong();
            System.out.println(fun(l, r));
        }
    }

    public static long fun(long l, long r) {
        long ln = getN(l)-1;
        long left = f(l, ln);
        long posL=(left)*(1+left)/2;
        long sl = getSum(ln)+posL;

        long rn=getN(r)-1;
        long right=f(r,rn);
        long posR=(right)*(1+right)/2;
        long sr=getSum(rn)+posR;

        return sr-sl+left;
    }
    //前n轮的结果
    public static long getSum(long n){
        long res=1;
        long pre=1;
        for (long i = 2; i <= n; i++) {
            pre=pre+i;
            res+=pre;
        }
        return res;
    }

    //求出x位置的值
    public static long f(long x,long n) {
        long sn = ((1 + n) * n) / 2;
        return x-sn;
    }
    //返回x位置在第几次循环
    public static long getN(long x) {
        return (long) Math.ceil((Math.sqrt((1 + 8 * x)) - 1) / 2); //x在第几轮
    }
}

